package com.vue.vuedemo.Controller;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.vue.vuedemo.pojo.Persons;
import com.vue.vuedemo.pojo.Personsteams;
import com.vue.vuedemo.service.PersonService;
import com.vue.vuedemo.service.PersonsTeamsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
@CrossOrigin(origins = {"http://localhost:8080"}) //当前网站向另一个网站请求数据就是跨域
@Controller
public class PersonsTeamsController {

    @Resource
    private PersonsTeamsService personsTeamsService;

    //根据人员编号查询人员与厂商信息
    @GetMapping(value = "personsTeamsFindAll")
    public List<Personsteams> findAll(Integer pTpId, HttpSession session){
        System.out.print("ptpId:"+pTpId);
        List<Personsteams> list =  personsTeamsService.findShow(pTpId);
        return list;
    }

    public Integer num;
    //人员喜欢的厂商表添加
    @GetMapping(value = "personsTeamsAdd")
    public Integer add(Integer pTpId, Integer pTtId, Personsteams personsteams, HttpSession session){
        if(personsTeamsService.PTidshow(pTpId,pTtId) == null || personsTeamsService.PTidshow(pTpId,pTtId).equals("")){
            try {
                personsteams.setPtPid(pTpId);
                personsteams.setPtTId(pTtId);
                personsTeamsService.addPT(personsteams);
                num = 1; //成功
            }catch (Exception ex){
                num = 2; //失败
            }
        }else{
            num = 3;
        }
        return num;
    }

    //人员喜欢的厂商表删除
    @GetMapping(value = "personsTeamsDel")
    public Integer del(Integer ptId){
        try {
            personsTeamsService.delPT(ptId);
            num = 1; //成功
        }catch (Exception ex){
            num = 2; //失败
        }
        return num;
    }

}
